package actor

// Props 定义创建actor的配置
type Props struct {
	actorProducer        Producer
	mailboxSize          int32
	mailboxScheduleCount int32
	supervisorFunc       SupervisorFunc
}

func newProps() *Props {
	p := &Props{
		mailboxSize:          1000,
		mailboxScheduleCount: 100,
		supervisorFunc:       defaultSupervisorFunc,
	}
	return p
}

func (props *Props) WithInstance(a IActor) *Props {
	props.actorProducer = makeProducerFromInstance(a)
	return props
}

func (props *Props) WithProducer(p Producer) *Props {
	props.actorProducer = p
	return props
}

func (props *Props) WithMailbox(size int32, scheduleCount int32) *Props {
	props.mailboxSize = size
	props.mailboxScheduleCount = scheduleCount
	return props
}

func (props *Props) WithSupervisor(f SupervisorFunc) *Props {
	props.supervisorFunc = f
	return props
}

func FromInstance(a IActor) *Props {
	p := newProps()
	p.actorProducer = makeProducerFromInstance(a)
	return p
}

func FromFunc(f ActorFunc) *Props {
	return FromInstance(f)
}

func FromProducer(actorProducer Producer) *Props {
	p := newProps()
	p.actorProducer = actorProducer
	return p
}

func makeProducerFromInstance(a IActor) Producer {
	return func() IActor {
		return a
	}
}
